import 'package:enterprise_v6_app/app/components/custom_modele/custom_field.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/list.dart';
import 'package:enterprise_v6_app/app/modules/application/education/personal_profile/basic/basic_controller.dart';

const _blue = Color(0xFF5C6DFF);

class EducationProfileBasicView extends StatelessWidget {
  EducationProfileBasicView({super.key});

  final controller = Get.put(EducationProfileBasicController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        return ListView(
          children: [
            Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(10.w),
              ),
              child: Column(
                children: <Widget>[
                  CustomField(
                    title: '职工姓名',
                    right: CustomField.input(
                      controller: controller.nameCtrl,
                      onChanged: (p0) {
                        controller.onSaveChanges();
                      },
                    ),
                  ),
                  CustomField(
                    title: '性别',
                    right: CustomField.select(
                      options: ['男', '女', '保密'],
                      selected: controller.sex,
                      callback: (p0) {
                        controller.sex = p0;
                        controller.update();
                        controller.onSaveChanges();
                      },
                    ),
                  ),
                  CustomField(
                    title: '手机号',
                    right: CustomField.input(
                      controller: controller.phoneCtrl,
                      onChanged: (p0) {
                        controller.onSaveChanges();
                      },
                    ),
                  ),
                  CustomField(
                    title: '学历',
                    right: CustomField.select(
                      options: ['博士', '硕士', '本科', '大专', '中专', '高中及以下'],
                      selected: controller.education,
                      callback: (p0) {
                        controller.education = p0;
                        controller.update();
                        controller.onSaveChanges();
                      },
                    ),
                  ),
                  CustomField(
                    title: '专业',
                    right: CustomField.input(
                      controller: controller.majorCtrl,
                      onChanged: (p0) {
                        controller.onSaveChanges();
                      },
                    ),
                  ),
                  CustomField(
                    title: '电子邮箱',
                    right: CustomField.input(
                      controller: controller.emailCtrl,
                      onChanged: (p0) {
                        controller.onSaveChanges();
                      },
                    ),
                  ),
                ].joinWith(Divider(
                  height: 1.w,
                  color: const Color(0xffECEEF3),
                )),
              ),
            ),
            AppGaps.vGap10,
            _buildBottom(),
          ],
        );
      },
    );
  }

  Widget _buildBottom() {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 5.w),
      child: InkWell(
        onTap: () {
          Get.showOverlay(asyncFunction: () async {
            await controller.profile.updateProfile();
          });
        },
        child: Container(
          padding: EdgeInsets.symmetric(vertical: 9.w),
          decoration: BoxDecoration(
            color: _blue,
            borderRadius: BorderRadius.circular(44.w),
          ),
          alignment: Alignment.center,
          child: Text(
            '更新基本信息',
            style: TextStyle(
              fontSize: 16.w,
              color: Colors.white,
            ),
          ),
        ),
      ),
    );
  }
}
